from file_define import TextFileReader,JsonFileReader,FileReader
from data_define import Record
from pymysql import Connection

text_file = TextFileReader("D:/date.txt")
json_file = JsonFileReader("D:/date1.txt")

jan_data: list[Record] = text_file.read_data()
feb_data: list[Record] = json_file.read_data()

all_data = jan_data+feb_data

con = Connection(
    host="localhost",
    port=3306,
    user="root",
    password="123456",
    autocommit=True
)

cursor = con.cursor()

con.select_db("test")

for record in all_data:
    sql = (f"insert into orders(order_date,order_id,money,province) " \
           f"values('{record.date}','{record.order_id}',{record.money},'{record.province}')")
    cursor.execute(sql)

    # print(sql)
con.close()